ECE3730J RC2
Basically, we are using MCU to communicate with the LCD controller (HD44780).
Datasheet for HD44780: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
LCD Controller Pin
- VSS (Pin 1): Ground (GND).
- VDD (Pin 2): Power supply (usually +5V).
Note: If you use J-link debugger to power the board, the output voltage at+5V
pin will not be 5V, maybe around 2.8V, so remember to use the 5V power supply wire to power the board. - VO (Pin 3): Contrast adjustment pin. Usually connected to a potentiometer to adjust the contrast.
- RS (Pin 4): Register select pin. Low for instruction register, high for data register.
- RW (Pin 5): Read/Write pin. Low for write operation, high for read operation. Usually grounded (write mode).
- E (Pin 6): Enable pin. The LCD controller only captures (grabs) the data presented at its register lines(D0-D7) only when the E pin “transitions” from high to low.
- D0-D7 (Pins 7-14): Data bus pins. Used for communication with the microcontroller in either 4-bit (D4-D7) or 8-bit (D0-D7) mode.
- A (Pin 15): For the backlight. Typically connected to +5V.
- K (Pin 16): For the backlight. Typically grounded (GND).
Connection with STM32
Some Useful Charts
From datasheet
- Four operation **IR: instruction register** **DR: data register**
In this Lab, we will mainly use the first and third operation
Instruction
DDRAM
CGRAM
Application Example
Send Command to LCD Controller
Recall the operation:
- Set the pin of
RS
&R/W
to low. - Set
E
to high, preparing for the data transfer. - Set
D7-D0
to the desired instruction(8-bit). - Set
E
to low
Sample code:
1 | void LCD_Write_Command(uchar Com) { |
Write Data To DDRAM
Recall the operation:
Set the pin of
RS
to high andR/W
to low.Set
E
to high, preparing for the data transfer.Set
D7-D0
to the desired address.Set
E
to low
Sample code:
1 | void LCD_Write_Data(uchar dat) { |
Init LCD
1 |
|
Display Charactor
First we need to set the cursor position
The cursor position is basically the DDRAM address that you want to write data in, which is corresponding to the display location on LCD screen.
1 | void LCD_Set_Position(uchar x, uchar y) { |
If we want to display a character at first line, first column:
1 | LCD_Set_Position(0,0); |
Then, we need to write data into DDRAM[addr] to tell the LCD which character you want to display, for example “J”.
1 | LCD_Write_Data("J"); // send the ascii code |
Putting them all together:
1 | void LCD_Display_Char(uchar Char, uchar x, uchar y) |
Display String
The cursor will shift right (because we set increment
entry mode) after each write_data
operation, so displaying a string is quite simple.
1 | void LCD_Display_Char(uchar Char, uchar x, uchar y) // 显示字符ASCII码 |
Demo
…